<template>
    <div>
        <a-modal
            :visible="handleModalVisible"
            :title="form.id?'编辑':'添加'"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="60%"
            :dialog-style="{ margin: '0 auto'}"
            wrapClassName="internalControl-full-modal"
            @cancel="closeVisible"
            >
            <a-form-model
                ref="ruleForm"
                :model="form"
                :rules="rules"
                :label-col="labelCol"
                :wrapper-col="wrapperCol"
                >
                <a-form-model-item ref="name" label="姓名" prop="fxm">
                    <a-input v-model="form.fxm"/>
                </a-form-model-item>
                <a-form-model-item label="入党状态" prop="frdzt">
                    <a-select v-model="form.frdzt">
                    <a-select-option value="入党申请">
                        入党申请
                    </a-select-option>
                    <a-select-option value="积极分子">
                        积极分子
                    </a-select-option>
                    <a-select-option value="发展对象">
                        发展对象
                    </a-select-option>
                    <a-select-option value="预备党员">
                        预备党员
                    </a-select-option>
                    <a-select-option value="正式党员">
                        正式党员
                    </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="入党申请时间" required prop="frdsqsj">
                    <a-date-picker
                        v-model="form.frdsqsj"
                        type="date"
                        style="width: 100%;"
                        />
                </a-form-model-item>
                <a-form-model-item label="确定发展对象时间	" required prop="fqdfzdxsj">
                    <a-date-picker
                        v-model="form.fqdfzdxsj"
                        type="date"
                        style="width: 100%;"
                        />
                </a-form-model-item>
                <a-form-model-item label="确定预备党员时间" required prop="fqdybdysj">
                    <a-date-picker
                        v-model="form.fqdybdysj"
                        type="date"
                        style="width: 100%;"
                        />
                </a-form-model-item>
                <a-form-model-item label="确定入党时间" required prop="fqdrdsj">
                    <a-date-picker
                        v-model="form.fqdrdsj"
                        type="date"
                        style="width: 100%;"
                        />
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>
</template>
<script>
import { dyAdd,dyEdit } from './service/index.js'
export default {
    data() {
        return {
            handleModalVisible: false,
            labelCol: { span: 6 },
            wrapperCol: { span: 14 },
            form: {
                fqdfzdxsj: "",
                fqdjjfzsj: "",
                fqdrdsj: "",
                fqdybdysj: "",
                frdsqid: "",
                frdsqsj: "",
                frdzt: "",
                fuserid: "",
                fxm: "",
                id: "",
            },
            kongForm: {},
            rules: {
                fxm: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
                frdzt: [{ required: true, message: '请选择入党状态', trigger: 'change' }],
                frdsqsj: [{ required: true, message: '请选择入党申请时间', trigger: 'change' }],
                fqdfzdxsj: [{ required: true, message: '请选择确定发展对象时间', trigger: 'change' }],
                fqdybdysj: [{ required: true, message: '请选择确定预备党员时间', trigger: 'change' }],
                fqdrdsj: [{ required: true, message: '请选择确定入党时间', trigger: 'change' }],
            },
        };
    },
    created() {
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    methods: {
        // 右上角关闭后的回调
        closeVisible(e){
            this.$emit('success')
            this.handleModalVisible = false
            this.form = {...this.kongForm}
        },
        onSubmit() {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    let data = this.form
                    if(this.form.id){
                        dyEdit(data).then(res => {
                            if(res.code == 200){
                                this.$message.success(res.message)
                            } else {
                                this.$message.warning(res.message)
                            }
                        })
                    } else {
                        dyAdd(data).then(res => {
                            if(res.code == 200){
                                this.$message.success(res.message)
                            } else {
                                this.$message.warning(res.message)
                            }
                        })
                    }
                } else {
                    //console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm() {
            this.$refs.ruleForm.resetFields();
        },
    },
};
</script>
